import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';

const baseUrl = '/parts/api/v1';

const initDesc = formatMessage({
    id: 'api.message.initDesc',
    defaultMessage: '初始化界面'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询包装单元数据'
});
const exportDesc = formatMessage({
    id: 'api.exportDesc',
    defaultMessage: '导出包装单元数据'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/packingListTrack/init`, null, dto.InitDataStruct)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, initDesc));
// 查询包装单元列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/packingListTracks?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 导出
export const exportParts = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/packingListTracks/export?${queryString}`, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};
